
local nianxing = fk.CreateSkill{
  name = "xiaobai__nianxing",
  dynamic_desc = function (self, player)
    local text = "xiaobai__nianxing_prompt1:"
    if player:getMark("nianxing_discard")==0 then
        text = text.."xiaobai__nianxing_prompt2:"
    else
      text = text .. ":"
    end
    if player:getMark("nianxing_jink")==0 then
      text = text.."xiaobai__nianxing_prompt3"
    else
    text = text .. ""
  end
    return text
  end,
}

Fk:loadTranslationTable{
  ["xiaobai__nianxing"] = "辇幸",
  [":xiaobai__nianxing"] = "每回合限一次，你可以使用或弃置一张装备牌，"..
    "视为使用一张【无懈可击】或【闪】，当你选择了“弃置”或“使用【闪】”后，删去对应的另一选项。",
  [":xiaobai__nianxing_prompt1"] = "每回合限一次，你可以{1}弃置一张装备牌，视为使用一张{2}【闪】，当你选择了“弃置”或“使用【闪】”后，删去对应的另一选项。",
  ["xiaobai__nianxing_prompt2"] = "使用或",
  ["xiaobai__nianxing_prompt3"] = "【无懈可击】或",
  ["#nianxiang_choose_cost"] = "辇幸：请选择使用或弃置一张装备牌",
  ["snianxing_choose"] = "辇幸",
  ["nianxing_usecard"] = "使用一张装备牌",
  ["nianxing_discard"] = "弃置一张装备牌",


  ["$xiaobai__nianxing1"] = "一簇相倾，百丛相妒，芳心何怕东君误。",
  ["$xiaobai__nianxing2"] = "桃李争春，我随孟夏长停步。",
}

nianxing:addEffect("viewas", { 
  pattern = "jink,nullification",
  anim_type = "defensive",
  interaction = function()
    local all_names = {
      "jink","nullification"
    }
    if Self:getMark("nianxing_jink")>0 then
      all_names = {
        "jink"
      }
    end
    local names = {}
    for _, name in ipairs(all_names) do
      local card = Fk:cloneCard(name)
      if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return UI.CardNameBox {choices = names}
  end,
  card_filter = Util.FalseFunc,
  before_use = function (self, player, use)
    local room = player.room
    local done, use = room:askToUseActiveSkill(player,{
      skill_name = "nianxing_choose",
      prompt = "#nianxiang_choose_cost"})
    if not done or not use then return nianxing.name end
    if use.interaction == "nianxing_discard" then
      room:addPlayerMark(player,"nianxing_discard")
      room:throwCard(use.cards,nianxing.name,player,player)
      if not player.dead then return end
    else
      room:useCard{
        card = Fk:getCardById(use.cards[1]),
        from = player,
        tos = {player},
      } 
      if not player.dead then return end
    end
    return nianxing.name
  end,
  view_as = function (self,cards)
    if #cards ~= 0 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = nianxing.name
    return card
  end,
  after_use = function (self, player, use)
    if use.card.trueName == "jink" then
      player.room:addPlayerMark(player,"nianxing_jink")
    end
  end,
  enabled_at_response = function (self, player, response)
    return not response and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard("jink")) or (player:getMark("nianxing_jink") == 0) and 
      table.find(player:getCardIds("he"),function (element, index, array)
        return Fk:getCardById(element).type == Card.TypeEquip
      end)
  end
})


local nianxing_choose = fk.CreateSkill{
  name = "nianxing_choose",
}

nianxing_choose:addEffect("active",{
  interaction = function ()
    local all_choices = {"nianxing_usecard", "nianxing_discard"}
    if Self:getMark("nianxing_discard") == 0 then
      return UI.ComboBox{
        choices = all_choices,
        all_choices = all_choices,
      }
    else
      return UI.ComboBox{
        choices = {all_choices[2]},
        all_choices = {all_choices[2]},
      }
    end
  end,
  card_num = 1,
  card_filter = function (self, player, to_select, selected)
    if not self.interaction.data or (selected and #selected>0)  then return end
    if self.interaction.data == "nianxing_usecard" then
      return table.contains(player.player_cards[Player.Hand], to_select) and Fk:getCardById(to_select).type == Card.TypeEquip
    else
      return Fk:getCardById(to_select).type == Card.TypeEquip
    end
  end
})

local skels = {}

table.insert(skels, nianxing)
table.insert(skels, nianxing_choose)

return skels